<template>
  <div class="app-container">
    <el-timeline>
      <el-timeline-item
        v-for="(item ,index) in warnList"
        :key="index"
        :timestamp="formatDate(item.timestamp)"
        placement="top"
      >
        <el-card>
          <el-row :gutter="20">
            <el-col :span="12">
              <el-input v-model="item.raw" type="textarea" :rows="20" />
            </el-col>
            <el-col :span="12">
              <el-input v-model="item.msg" type="textarea" :rows="20" />
            </el-col>
          </el-row>
        </el-card>
      </el-timeline-item>
    </el-timeline>
    <div style="text-align: right;margin: 15px 0">
      <el-pagination
        background
        :current-page.sync="currentPage"
        :page-size="pageSize"
        layout="total,sizes,prev,pager,next,jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>

  </div>
</template>

<script>
import { pageGetDeviceWarnUpload } from '@/api/iot/iotDeviceWarnUploadApi'
import {
  failureNotice,
  formatDate
} from '@/util/common'
import {
  getPageSize,
  setPageSize,
  getUserId
} from '@/util/storage'
export default {
  name: 'DeviceWarnUpload',
  data() {
    return {
      warnList: [],
      currentPage: 1,
      total: 0,
      pageSize: getPageSize(),
      userId: getUserId()
    }
  },
  created() {
    this.pageGetDeviceWarnUpload()
  }, methods: {
    formatDate(data) {
      return formatDate(this, data)
    },
    handleSizeChange(val) {
      this.pageSize = val
      setPageSize(this.pageSize)
      this.pageGetDeviceWarnUpload()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.pageGetDeviceWarnUpload()
    },
    pageGetDeviceWarnUpload() {
      pageGetDeviceWarnUpload({
        userId: this.userId,
        pageSize: this.pageSize,
        currentPage: this.currentPage
      }).then(res => {
        const { code, data } = res
        if (code === '200') {
          this.total = data.total
          this.warnList = data.data
        }
      })
    }
  }

}
</script>


